#!/usr/bin/env python

from page import page
import sys, time

class menu(page):
	"""
	Superclass for all pages 

	it basically just prints to stdout this page

	>>> p = page()
	"""
	def __init__(self):
		self.titlestr = "<b>F</b>ood <b>S</b>torage <b>M</b>anager"
		self.headingstr = "Main Page"

	def log(self, msg):
		sys.stderr.write(msg+"\n")

	def logic(self):
		pass

	def render(self):
		self.logic()
		self.encoding()
		self.html()

	############### page parts #################

	def encoding(self):
		print """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">"""

	def html(self):
		self.start_html()
		self.head()
		self.body()
		self.end_html()

	def start_html(self):
		print "<html>"

	def head(self):
		self.title()
		self.head_script()
		self.css()

	def title(self):
		print "<title>%s</title>" % self.titlestr.replace("<b>","").replace("</b>","")

	def head_script(self):
		pass

	def css(self):
		print """<style><!--
		body,td,a,p,.h{font-family:arial,sans-serif;}
		.q{color:#0000cc;}
		a {font-family: Arial, sans-serif; font-size: medium; color: #003366; text-decoration: none}
		a:hover{color: #0066CC}
		//-->
		</style>"""
	
	def body(self):
		self.start_body()
		self.heading()
		self.menu()
		self.footer()
		self.end_body()
	
	def start_body(self):
		print "<body style='font-family: sans-serif;'>"

	def heading(self):
		print """%s
		<br />
		<span style="font-weight: bold;">%s<span>
		<p />""" % (self.titlestr, self.headingstr)

	def menu(self):
		menu = """
		<table style="text-align: left; width: 20%;" border="1" cellpadding="3"
			cellspacing="0">
		<tbody>
		<tr><td><a href="add_items.py">Add Items</a></td></tr>
		<tr><td><a href="del_items.py">Remove Items</a></td></tr>
		<tr><td><a href="add_upc_type.py">Add Custom UPC</a></td></tr>
		<tr><td><a href="type_list.py">Item Categories</a></td></tr>
		<tr><td><a href="reports.py">Reports</a></td></tr>
		</tbody>
		</table>
		"""
		print menu

	def footer(self):
		pass

	def end_body(self):
		print "</body>"

	def end_html(self):
		print "</html>"

################ Other Methods #################

class runner:
	def _test(self):
		pass

	def _doctest(self):
		import doctest, p
		doctest.testmod(p)

if __name__ == "__main__":
	r = runner()
	getattr(r, "_"+sys.argv[1])()
else:
	menu().render()
